package com.example.abstractfactory;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * @version 1.0.0
 * @className: RedisUtils
 * @description: 模拟单机Redis服务
 * 模拟Redis功能，也就是假定目前所有的系统都在使用的服务
 * 类和方法名次都固定写死到各个业务系统中，改动略微麻烦
 * @author: rosszhang
 * @date: 2022/6/8 17:05
 */
@Slf4j
public class RedisUtils {
    private Map<String, String> dataMap = new ConcurrentHashMap<>();

    public String get(String key) {
        log.info("Redis获取缓存数据key:{}", key);
        return dataMap.get(key);
    }

    public void set(String key, String value) {
        log.info("Redis写入缓存数据key:{}，val:{}", key, value);
        dataMap.put(key, value);
    }

    public void set(String key, String value, long timeout, TimeUnit timeUnit) {
        log.info("Redis写入缓存数据key:{}，val:{},timeout:{},timeUnit:{}", key, value, timeout, timeUnit);
        dataMap.put(key, value);
    }

    public void del(String key) {
        log.info("Redis删除数据，key:{}", key);
        dataMap.remove(key);
    }
}
